package vis.items.visualItem;

import java.util.Observable;
import java.util.Observer;

import processing.core.PApplet;

public abstract class AbstractSketch extends PApplet implements Observer {
	private static final long serialVersionUID = 2029993390802320215L;

	public static final int WORLD_WIDTH = 724;
	public static final int WORLD_HEIGHT = 668;
	public static final int FRAME_TO_UPDATE_LOGIC = 40;

	private String name;

	public String getName() {
		return name;
	}

	public AbstractSketch(String name) {
		this.name = name;
	}

	public boolean matchSketch(AbstractSketch otherSketch) {
		return this.name.equals(otherSketch.getName());
	}

	@Override
	public void init() {
		super.init();
	}

	@Override
	public void setup() {
		size(WORLD_WIDTH, WORLD_HEIGHT);
	}

	private int nFrameCount = 0;

	@Override
	public void draw() {
		nFrameCount++;
		if (FRAME_TO_UPDATE_LOGIC == nFrameCount) {
			nFrameCount = 0;
			updateLogicInterval();
		}

		updateDataInOneFrame();
		drawFrame();
	}

	public abstract void updateLogicInterval();

	public abstract void updateDataInOneFrame();

	public abstract void drawFrame();

	@Override
	public void update(Observable arg0, Object obj) {
	}

}
